<%- include('header') %>

<script>
    function displayHideUI(view_id)
    {
        var ui =document.getElementById(view_id);
        ui.style.display="none";
    }
    function displayShowUI(view_id)
    {
        var ui =document.getElementById(view_id);
        ui.style.display="";//display为空的话会好使，为block会使后边的空间换行
    }
    function deletePhotos()
    {
        displayHideUI("photos");
        displayShowUI("upload_photo");
    }
</script>

<div class="ui grid">
    <div class="four wide column">
        <a class="avatar"
           href="/posts?author=<%= user._id %>"
           data-title="<%= user.name %> | <%= ({m: '男', f: '女', x: '保密'})[user.gender] %>"
           data-content="<%= user.bio %>">
            <% if (post.author.avatar) { %>
            <img class="avatar" src="/img/<%= user.avatar %>">
            <% } %>
            <label><%= post.author.name %></label>
        </a>
    </div>

    <div class="eight wide column">
        <form class="ui form segment" method="post" enctype="multipart/form-data" action="/posts/<%= post._id %>/edit">
            <div class="field required">
                <label>标题</label>
                <input type="text" name="title" value="<%= post.title %>">
            </div>
            <div class="field required">
                <label>内容</label>
                <textarea name="content" rows="5"><%= post.content %></textarea>
            </div>
            <% if (post.photos) { %>
            <div id="photos">
                <img class="photos" width="20%" height="20%" src="/img/<%= post.photos %>">
                <div>
                    <label onclick="deletePhotos()">删除图片</label>
                </div>
            </div>
            <% } %>
            <div id="upload_photo" style="display: none">
                <label>照片</label>
                <input type="file" name="photos">
            </div>
            <input type="submit" class="ui button" value="发布">
        </form>
    </div>
</div>

<%- include('footer') %>
